package com.tdd;

import java.math.BigDecimal;

public class PrimeFactors implements Operation {
	public static final BigDecimal TWO = new BigDecimal(2);

	public void operate(HpStack values) {
		BigDecimal operand = values.pop();

		BigDecimal current = TWO;

		while (current.compareTo(operand) <= 0) {
			while (operand.remainder(current).compareTo(BigDecimal.ZERO) == 0) {
				values.push(current);
				operand = operand.divide(current);
			}
			current = current.plus(BigDecimal.ONE);
		}
	}
}
